package com.example.demo.advice;

import com.example.demo.ResultResponse;
import org.springframework.core.MethodParameter;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 个性化的返回数据加密
 */
@RestControllerAdvice
public class EncryptResponseBody extends com.kming.crypto.EncryptResponseBody {
    @Override
    public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
        Object obj = encryptData(body, returnType);
        return new ResultResponse<>(obj);
    }
}
